<template>
  <div v-if="props.rowData">
    {{ props.supplierId }} --{{ formData.suppliernamedelivery_id }}
    <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
      <el-form-item label="备注" prop="remarks">
        <el-input v-model="formData.remarks" name="remarks" clearable />
      </el-form-item>

      <el-form-item label="采购订单id" prop="purchaseorder_id" :rules="[{ required: true, message: '采购订单id必须填写' }]">
        <el-input v-model="formData.purchaseorder_id" name="purchaseorder_id" clearable />
      </el-form-item>

      <el-form-item label="物流行号id" prop="purchaseorderschedule_id" required>
        <el-input type="text" v-model="formData.purchaseorderschedule_id" name="purchaseorderschedule_id" clearable />
      </el-form-item>
      <el-form-item label="数量" prop="quantity" required>
        <el-input-number v-model="formData.quantity" :min="1" />
      </el-form-item>
      <el-form-item label="已暂收的数量" prop="thequantity">
        <el-input-number v-model="formData.thequantity" :min="1" :max="formData.quantity" />
      </el-form-item>
      <el-form-item label="送货日期" prop="deliverydate">
        <el-date-picker v-model="formData.deliverydate" type="date" placeholder="选择送货日期" required />
      </el-form-item>
      <el-form-item label="品名列表" prop="suppliernamedelivery_id" required>
        <!-- <el-input type="textarea" v-model="formData.suppliernamedelivery_id" name="suppliernamedelivery_id" clearable /> -->
        <el-select v-model="formData.suppliernamedelivery_id"  placeholder="选择品名列表" size="large">
          <el-option v-for="item in category" :key="item.id" :label="item.fseqname" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="箱号" prop="number">
        <el-input-number v-model="formData.number" :min="1"  />
      </el-form-item>

      <div class="flex justify-end">
        <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
      </div>
    </el-form>
  </div>
</template>
  
  <script lang="ts" setup>
import { useCreate } from '/admin/composables/curd/useCreate'

import { useShow } from '/admin/composables/curd/useShow'
import { onMounted } from 'vue'
import http from '/admin/support/http'

const optionslist = ref([])
// const options = ref([])

// const getOptions = () => {
//   http.get('/promanagement/listtype').then(r => {
//     optionslist.value = r.data.data
//   })
// }

// getOptions()

const props = defineProps({
  primary: String | Number,
  api: String,
  rowData: Object,
  supplierId: String | Number,
})
let category = ref([])
const getcategoryApi = () => {
  http.get(`/purchasing/categoryApi/${props.supplierId}`).then(r => {
    // console.log(r.data)
    category.value =  r.data.data
    // let arr = r.data.data
    // let obj = {}
    // arr.forEach((item, index) => {
    //   obj[index] = {}
    //   obj[index].value = item.id
    //   obj[index].label = item.fseqname
    // })
    // console.log(obj)
    // category.value = obj
    // console.log(category.value)
  })
}
getcategoryApi()
const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)
console.log(formData.value)
console.log(props.rowData)

formData.value = props.rowData

if (props.primary) {
  useShow(props.api, props.primary, formData)
}

const options = [
  {
    value: 'Option1',
    label: 'Option1',
  },
  {
    value: 'Option2',
    label: 'Option2',
  },
]

const emit = defineEmits(['close'])
onMounted(() => {
  close(() => emit('close'))
})
</script>
  